package com.gzhryc.jdbc;

import java.sql.SQLException;
import java.util.List;

import com.gzhryc.jdbc.models.Db;
import com.gzhryc.jdbc.models.DbColumn;
import com.gzhryc.jdbc.models.DbTable;
import com.gzhryc.jdbc.models.IndexInfo;

/**
 * 数据库操作接口
 * @author 张浩
 * @version 1.0
 */
public interface DbHelper {

	/**
	 * 创建数据库
	 * @param database
	 * @return
	 */
	public boolean createDb(String database) throws SQLException;
	
	/**
	 * 删除数据库
	 * @param database
	 * @return
	 */
	public boolean deleteDb(String database) throws SQLException;
	
	/**
	 * 检查数据库是否存在
	 * @param database
	 * @return
	 */
	public boolean existDb(String database) throws SQLException;
	
	/**
	 * 获取所有数据库信息
	 * @return
	 */
	public List<Db> findAllDb() throws SQLException;
	
	/**
	 * 根据数据类创建数据库表
	 * @param clazz
	 * @return
	 */
	public boolean createTable(Class<?> clazz) throws SQLException;
	
	/**
	 * 根据数据类创建数据库表，自定义表名
	 * @param tableName
	 * @param clazz
	 * @return
	 * @throws SQLException
	 */
	public boolean createTable(String tableName,Class<?> clazz) throws SQLException;
	
	/**
	 * 重命名数据库表
	 * @param tableName
	 * @param newTableName
	 * @return
	 * @throws SQLException
	 */
	public boolean renameTable(String tableName,String newTableName) throws SQLException;
	
	/**
	 * 创建视图
	 * @param clazz
	 * @return
	 * @throws SQLException
	 */
	public boolean createView(Class<?> clazz) throws SQLException;
	
	
	public boolean createView(String viewName,String asSql) throws SQLException;
	
	/**
	 * 创建或修改索引
	 * @param tableName
	 * @param clazz
	 * @return
	 * @throws SQLException
	 */
	public void createOrUpdateIndex(String tableName,Class<?> clazz) throws SQLException;
	
	/**
	 * 创建或修改唯一约束
	 * @param tableName
	 * @param clazz
	 * @return
	 * @throws SQLException
	 */
	public void createOrUpdateUniqueKey(String database,String tableName,Class<?> clazz) throws SQLException;
	
	/**
	 * 获取数据库所有表信息
	 * @param database
	 * @return
	 */
	public List<DbTable> findAllDbTable(String database) throws SQLException;
	
	/**
	 * 删除数据库中某张表
	 * @param tableName
	 * @return
	 */
	public boolean deleteTable(String tableName) throws SQLException;
	
	/**
	 * 检查表是否存在
	 * @param tableName
	 * @return
	 */
	public boolean existTable(String database,String tableName) throws SQLException;
	
	/**
	 * 检查表视图是否存在
	 * @param database
	 * @param viewName
	 * @return
	 * @throws SQLException
	 */
	public boolean existView(String database,String viewName) throws SQLException;
	
	/**
	 * 获取数据库表中所有列信息
	 * @param database
	 * @param tableName
	 * @return
	 */
	public abstract List<DbColumn> findAllDbColumn(String database,String tableName) throws SQLException;
	
	/**
	 * 获取数据库表中所有索引
	 * @param tableName
	 * @return
	 * @throws SQLException
	 */
	public abstract List<IndexInfo> findAllIndex(String tableName) throws SQLException;

	public List<String> findAllUniqueKeyName(String database,String tableName) throws SQLException;
}
